package com.shop.core;

import com.g3net.tool.CachedClientFactory;
import com.shop.util.Config;

/**
 * 用来做数据缓存:将数据存放在memcache中
 * @author yuxiaowei
 *
 */
public class DataCache {
	
	public static String getString(String key){
		return (String)CachedClientFactory.getCachedClient(Config.CACHE_NAME).get(key);
	}
	/**
	 * 设置缓存
	 * @param key
	 * @param content	
	 * @param time	过期时间，单位为秒
	 */
	public static void setString(String key,String content,int time){
		if(time>0)
		{
			CachedClientFactory.getCachedClient(Config.CACHE_NAME).set(key, content,time);
		}else{
			CachedClientFactory.getCachedClient(Config.CACHE_NAME).set(key,content);
		}
	}
	
	
	public static Object getObject(String key){
		return CachedClientFactory.getCachedClient(Config.CACHE_NAME).get(key);
	}
	public static void delObject(String key){
		 CachedClientFactory.getCachedClient(Config.CACHE_NAME).delete(key);
	}
	/**
	 * 设置缓存
	 * @param key
	 * @param content	
	 * @param time	过期时间，单位为秒
	 */
	public static void setObject(String key,Object content,int time){
		if(time>0)
		{
			CachedClientFactory.getCachedClient(Config.CACHE_NAME).set(key, content,time);
		}else{
			CachedClientFactory.getCachedClient(Config.CACHE_NAME).set(key,content);
		}
	}

}
